package com.learn.hystrix.observable;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author Sunxiaoyu
 * Create in 20:23 2018/12/23
 */
public abstract class AbstractSubject implements Subject {
    private CopyOnWriteArrayList<Observer> observerList = new CopyOnWriteArrayList<>();

    @Override
    public void add(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void del(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    public void notifyObservers(String context) {
        observerList.forEach(observer -> observer.update(context));
    }
}
